package cn.mw.cmdb.config.MQTT;

import cn.mw.cmdb.entity.InstanceInfo;
import cn.mw.cmdb.entity.ModelInfo;
import cn.mw.cmdb.param.ModelSearchParam;
import cn.mw.cmdb.service.impl.CmdbServiceManage;
import cn.mw.cmdb.service.impl.CustomModelServiceImpl;
import cn.mw.cmdb.service.impl.InstanceServiceImpl;
import cn.mw.microMonitorCommon.util.SpringUtils;

import java.util.List;
import java.util.stream.Collectors;

import static cn.mw.cmdb.enums.ModelViewTypeEnum.cabinetView;

public class MqttCommonMethod {
    public static List<InstanceInfo> getAllCabinetInstnace() throws Exception {
        //根据利用U位管理模块Id，更新数据库中机柜的连接状态
        CmdbServiceManage cmdbServiceManage = SpringUtils.getBean(CmdbServiceManage.class);
        CustomModelServiceImpl customModelService = (CustomModelServiceImpl) cmdbServiceManage.getModelService(CustomModelServiceImpl.ID);
        ModelSearchParam modelSearchParam = new ModelSearchParam();
        modelSearchParam.setModelViewType(cabinetView.name());
        //获取所有机柜模型
        List<ModelInfo> modelInfos = customModelService.getListNotAuth(modelSearchParam);
        List<String> cabinetModelIds = modelInfos.stream().map(s -> s.getId()).collect(Collectors.toList());
        InstanceServiceImpl instanceService = (InstanceServiceImpl) cmdbServiceManage.getModelService(InstanceServiceImpl.ID);
        //获取所有机柜实例信息
        List<InstanceInfo> instanceInfoList = instanceService.doListByModelIdsNotAuth(cabinetModelIds);
        return instanceInfoList;
    }


}
